#!/bin/bash

#get this script real directory
SOURCE="$0"
while [ -h "$SOURCE"  ]; do # resolve $SOURCE until the file is no longer a symlink
    this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"
    SOURCE="$(readlink "$SOURCE")"
    # if $SOURCE was a relative symlink, 
    #we need to resolve it relative to the path 
    #where the symlink file was located
    [[ $SOURCE != /*  ]] && SOURCE="$this_script_dir/$SOURCE"
done
this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"

env_file=$this_script_dir/../shell/nat_type_checker/service/env.sh
source $env_file

if [ -n "$1" ] ; then
    if [ ! -d "$1" ] ; then
        echo "-- error, your set parameter $1, the path does not exist."
        exit 1 
    fi
fi


version=p2pcpp_v1.2.6.mac
tmp_dir=~/git/tmp
release_dir=~/git/p2pcpp_release/macos

if [ ! -d $tmp_dir ] ; then
    mkdir -p $tmp_dir
fi

if [ -d $tmp_dir/$version ] ; then 
    rm -r $tmp_dir/$version 
fi

cd $release_dir 
git pull

cd ~/git/p2pcpp/build 
cmake .. -DCMAKE_INSTALL_PREFIX=$tmp_dir/$version -DLINK_STATIC=ON&& make install
cmake .. -DCMAKE_INSTALL_PREFIX=~/run -DLINK_STATIC=OFF

#cp -rp ~/run $tmp_dir/$version

cd $tmp_dir
tar -zcf $version.tar.gz ./$version && cp -rp $version.tar.gz  $release_dir

cd $release_dir 
git add $version.tar.gz
git commit -m'add by pack.sh'
git push



